Programming Basics
Data Representation Size and Numeric Exercise
These exercises are designed to evaluate your knowledge, comprehension and application of the size of data units in a computer and how numeric data is represented, converted and operated upon. It is expected that you should be able to correctly answer all or nearly all of the questions and problems presented. You should do these exercises by yourself. This exercise represents the most foundational and elementary information to be mastered by anyone involved with computer programming.
1. Identify the size unit (bit, nibble, byte, word) and numeric type (binary, octal, decimal, hexadecimal) that the listed values most accurately occupy and represent.
Size Unit |
Numeric Type |
Value |
| | |
Size Unit |
Numeric Type |
Value |
||
A |
0101 |
| |
H |
$A |
||||
B |
%o721 |
| |
I |
10 |
||||
C |
$FEED |
| |
J |
%o17 |
||||
D |
17 |
| |
K |
111000100000 |
||||
E |
$73 |
| |
L |
%o20 |
||||
F |
0 |
| |
M |
3 |
||||
G |
01011010 |
| |
N |
436 |
2. Label the following diagram in terms of bit position and bit significance. The items to label on top are for bit significance and the items to label on the bottom are for bit position.
a. _______________________
b. _______________________
c. _______________________
d. _______________________
e. _______________________
3. Convert the following numbers into the missing representations.
Binary |
Decimal |
Octal |
Hexadecimal |
0000 |
|||
%o342 |
|||
197 |
|||
$D34F |
|||
10111001 |
|||
24687 |
|||
$123 |
|||
%o777 |
4. Fill in the missing representations. The decimal value and the two’s complement value should be equivalent. The two’s complement value is what would be stored by the computer to represent the negative decimal value.
Decimal |
One’s Complement |
Two’s Complement |
-12 |
||
10011011 |
||
-7 |
||
11110110 |
||
11100010 |
||
-212 |
||
-1497 |
||
1111000101010011 |
||
1000111100101010 |
5. Do the following arithmetic problems; show the last carry digit:
(assume binary numbers are represented in two’s complement format)
a. |
00001111 |
b. |
11101010 |
c. |
00110001 |
+ |
01111101 |
+ |
11101010 |
- |
00000111 |
= |
( )________ |
= |
( )________ |
= |
( )________ |
d. |
00011110 |
e. |
10101010 |
f. |
11100100 |
- |
10100111 |
- |
10100110 |
+ |
00011011 |
= |
( )________ |
= |
( )________ |
= |
( )________ |
6. This problem applies the knowledge and comprehension of numeric data representation and conversions.
Write pseudo code that implements different procedures to convert a binary number into decimal, octal and hexadecimal and visa versa. These procedures are bin2Decimal, bin2Octal, bin2Hex, decimal2Bin, hex2Bin and octal2Decimal are described as:
bin2Decimal – this procedure will be passed a string containing a valid binary number of arbitrary length. The binary number should be converted into its decimal equivalent and returned as a string.
bin2Octal – this procedure will be passed a string containing a valid binary number of arbitrary length. The binary number should be converted into its octal equivalent and returned as a string.
bin2Hex – this procedure will be passed a string containing a valid binary number of arbitrary length. The binary number should be converted into its hexadecimal equivalent and returned as a string.
decimal2Bin – this procedure will be passed a string containing a valid decimal number of arbitrary length. The decimal number should be converted into its binary equivalent and returned as a string.
hex2Bin – this procedure will be passed a string containing a valid hexadecimal number of arbitrary length. The hexadecimal number should be converted into its binary equivalent and returned as a string.
octal2Decimal – this procedure will be passed a string containing a valid octal number of arbitrary length. The octal number should be converted into its decimal equivalent and returned as a string.